﻿using System;
using Microsoft.Extensions.Logging;

namespace net.xBei.Helper {
    /// <summary>
    /// 
    /// </summary>
    public static class LoggerHelper {
        public static void Error(this ILogger logger, string correlationId, string message)
            => Error(logger, correlationId, message, null, null);
        public static void Error(this ILogger logger, string correlationId, string message, object? data, Exception? exception = null) {
            //=> logger.Error(correlationId, message, data, exception);
            //void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter);
            logger?.Log(LogLevel.Error, new EventId(0, correlationId), data, exception, (d, e) => message);
        }
        public static void Error<T>(this ILogger logger, string correlationId, string message, T data, Exception? exception = null) where T : class {
            logger?.Log(LogLevel.Error, new EventId(0, correlationId), data, exception, (d, e) => message);
        }
        public static void Error(this ILogger logger, string correlationId, object? data = null, Exception? exception = null) {
            logger?.Log(LogLevel.Error, new EventId(0, correlationId), data, exception, (d, e) => e?.Message ?? string.Empty);
        }
        public static void Error<T>(this ILogger logger, string correlationId, T? data = default, Exception? exception = null) where T : class {
            logger?.Log(LogLevel.Error, new EventId(0, correlationId), data, exception, (d, e) => e?.Message ?? string.Empty);
        }
        public static void Info(this ILogger logger, string correlationId, string message, object? data = null) {
            logger?.Log(LogLevel.Information, new EventId(0, correlationId), data, null, (d, e) => message);
        }
        public static void Info<T>(this ILogger logger, string correlationId, string message, T? data = default) {
            logger?.Log(LogLevel.Information, new EventId(0, correlationId), data, null, (d, e) => message);
        }
        public static void Debug(this ILogger logger, string correlationId, string message, object? data = null) {
            logger?.Log(LogLevel.Debug, new EventId(0, correlationId), data, null, (d, e) => message);
        }
        public static void Warning(this ILogger logger, string correlationId, string message, object? data = null) {
            logger?.Log(LogLevel.Warning, new EventId(0, correlationId), data, null, (d, e) => message);
        }
    }
}
